package com.aosgame;

import android.app.Activity;

import com.androidgame.fx.Game;
import com.androidgame.fx.Graphics;
import com.androidgame.fx.Screen;
import com.androidgame.fx.ScreenConfig;
import com.androidgame.fx.Input.TouchEvent;

public class MenuScreen extends Screen {

	public static final int BUTTON_START = 0;
	public static final int BUTTON_EXIT = 1;
	public static final int BUTTON_END = 2;
	
	private GameButton[] 	gameButton;

	public MenuScreen(Game game) {
		super(game);

		Graphics g = game.getGraphics();
		Assets.menu = g.newBitmap("menu.jpg");
		Assets.startButton = g.newBitmap("startbutton.png");
		Assets.offStartButton = g.newBitmap("offstartbutton.png");
		Assets.exitButton = g.newBitmap("exitbutton.png");
		Assets.offExitButton = g.newBitmap("offexitbutton.png");
		
		gameButton = new GameButton[BUTTON_END];
		gameButton[BUTTON_START] = new GameButton(Assets.startButton, Assets.offStartButton,
				(int)(ScreenConfig.virtualScreenWidth * 0.1), (int)(ScreenConfig.virtualScreenHeight * 0.5));
		gameButton[BUTTON_EXIT] = new GameButton(Assets.exitButton, Assets.offExitButton, 
				(int)(ScreenConfig.virtualScreenWidth * 0.1), (int)(ScreenConfig.virtualScreenHeight * 0.6));
	}
	
	@Override
	public boolean touchDown(TouchEvent event) {
		for(int i = 0; i < gameButton.length; i++) {
			gameButton[i].touchDown(event.x, event.y);
		}
		return false;
	}

	@Override
	public boolean touchDragged(TouchEvent event) {
		for(int i = 0; i < gameButton.length; i++) {
			gameButton[i].touchDragged(event.x, event.y);
		}
		return false;
	}

	@Override
	public boolean touchUp(TouchEvent event) {
		for(int i = 0; i < gameButton.length; i++) {
			if(gameButton[i].touchUp(event.x, event.y)) {
				if(i == BUTTON_START) {
					game.setScreen(new PlayScreen(game));
				} else if(i == BUTTON_EXIT) {
					((Activity)game).finish();
				}
				return true;
			}
		}
		return false;
	}
	
	@Override
	public void update(float deltaTime) {
		
	}

	@Override
	public void present(float deltaTime) {
		Graphics g = game.getGraphics();
		
		g.drawBitmap(Assets.menu, 0, 0);

		for(int i = 0; i < gameButton.length; i++) {
			gameButton[i].present(g);
		}
		
		game.getGameTime().present(g);
	}

	@Override
	public void pause() {
		
	}

	@Override
	public void resume() {
		
	}

	@Override
	public void dispose() {
		
	}



}
